import sys
import ChannelDict #pylint: disable=import-error

def generateDict(ch_l, ch_d):
    i = 0  
    start = False   # Dont start until *** is found
    name = ""       # Channel name
    fr = open(ch_l, 'r')
    fw = open(ch_d,'w')
    fw.write("ch_d = {\n")
    for l in fr.readlines():
        if "***" in l:
            start = True
            i+=1
        elif start and "#EXTINF" in l:
            name = l.split(sep=',')[1].strip('\n')
            i+=1
            fw.write(f"\t'{name}':{i},\n")
        else:
            i+=1
    fw.write("\t'': 0 \n")
    fw.write("}")
    fr.close()
    fw.close()
    print(ChannelDict.ch_d)



if __name__ == '__main__':
    channelList = sys.argv[1]
    channelDict = "ChannelDict.py"
    generateDict(channelList, channelDict)